import random
import math
# rano/wieczor sms/rozmowa dlugo/krotko max_czas_rozmowy 

# godziny pomiedzy 1 - 12
morning = [ 0.5/12.0, 0.1/12.0, 0.1/12.0, 0.1/12.0, 0.1/12.0, 0.1/12.0, 1.0/12.0,
           1.0/12.0, 2.0/12.0, 2.0/12.0, 2.0/12.0, 3.0/12.0]

# godziny pomiedzy 13 - 24
evening = [ 3.0/12.0, 2.0/12.0, 2.0/12.0, 2.0/12.0, 1.0/12.0, 1.0/12.0, 0.5/12.0,
           0.1/12.0,  0.1/12.0, 0.1/12.0, 0.1/12.0, 0.1/12.0]

def getTime(morning_evening):
    tm = random.random()
    to_add = 0
    minutes = random.randint(0, 60)
    if tm < morning_evening:
        table = morning
    else:
        table = evening
        to_add = 12
        
    t = random.random()
    last = 0
    for i in range(len(table)):
        if t < table[i] + last:
            return str(i + to_add) + ":" + str(minutes)
        last += table[i]
    return str(12 + to_add) + ":" + str(minutes)

def getSms(sms_call):
    i = random.random()
    if i < sms_call:
        return True
    else:
        return False
    
def getLong(long, max_time):
    r = (random.random() * long) ** 2
    return r * max_time
    
    
#def getNet(nets_prob):
#    ni = random.random()
#    last = 0
#    for i in range(len(nets_prob)):
#        if nets_prob[i] + last > ni:
#            return nets[i]
#        last += nets_prob[i]
#    return nests[-1]
    
def generateBilling(morning_evening, sms_call, long_time, max_time, how_many):
    billings = []
    for i in range(how_many):
        time_call = getTime(morning_evening)
        sms = getSms(sms_call)
        if not sms:
            long = getLong(long_time, max_time)
        else:
            long = -1
            
        #net = getNet(nets_prob)
        billings.append((time_call, sms, long))
            
    return billings

if __name__ == "__main__":
	for i in range(10000):
		f = open("billings/billing_" + str(i) + ".txt", "w")
		billings = generateBilling(random.random(),random.random(), random.random(), 10800.0, 500)
		for (time_call, sms, long) in billings:
			if sms:
				f.write(time_call + "  " + " sms\n")
			else:
				f.write(time_call + "  " + "  " + str(long) + "\n")